package com.lankystar.todolist.page.demo;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lankystar.common.Page;
import com.lankystar.todolist.model.Account;
import com.lankystar.todolist.model.Task;
import com.lankystar.todolist.service.IDemoService;

@Controller
@RequestMapping("/demo")
public class DemoAction {
	@Autowired
	private IDemoService demoService;

	@RequestMapping("/test")
	@ResponseBody
	public Account test() {
		Account account = new Account();
		account.setUsername("test");
		account.setUserpwd("test");
		account.setNickname("测试");
		account.setPhone("123456");
		account.setEmail("测试@测试.测试");
		return account;
	}

	@RequestMapping("/page")
	public ModelAndView page(Map<String, Object> info) {
		info.put("msg", "这是一条测试消息！");
		return new ModelAndView("demo/layout/demo.html", info);
	}

	@RequestMapping("/list")
	@ResponseBody
	public Page<Task> list(Page<Task> page) {
		return demoService.getTasks(page);
	}

	@RequestMapping("/testTx")
	@ResponseBody
	public List<Account> testTx() {
		try {
			demoService.editAccount();
		} catch (Exception e) {
		}
		return demoService.findAccounts();
	}
}
